﻿<!--
//formNum  默认为null为forms【0】
//isNeeded 是否为必填项，默认null（必填项）
//errMsg 提示消息，默认值为“此项不可为空！”
//检测非空
function CheckLength(val,maxlen,msg,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var smsg=(msg==null || msg=="")? "此项不可为空！":msg;
    var str = Trim(document.forms[formTarget].elements[val].value);
    if (str == "")
    {
        alert (smsg);
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    else if(str!="" && maxlen!=null)
    {
        if (str.length>maxlen)
        {
            alert("此项信息超长，最多可输入" + maxlen +"个字符，请重新输入！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
    }
    if (str.indexOf("\'")!= -1)
    {
        alert ("请不要使用英文单引号！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    document.forms[formTarget].elements[val].value = str;
    return true;
}
//检查文本框的长度及非法字符(可以为空)
function CheckLengthNovalue(val,maxlen,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var str = Trim(document.forms[formTarget].elements[val].value);
    if(str!="" && maxlen!=null)
    {
        if (str.length>maxlen)
        {
            alert("此项信息超长，最多可输入" + maxlen +"个字符，请重新输入！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
    }
    if (str.indexOf("\'")!= -1) {
        alert ("请不要使用英文单引号！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    document.forms[formTarget].elements[val].value = str;
    return true;
}
//检测姓名
function CheckName(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(CheckLength(val)){
        var charset = "0123456789";
        if (!CheckChar(charset, input, false)) {
            alert ("请输入文字！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        return true;
    }
    return false;
}
//检测姓名（可以为空）
function CheckNullName(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
        if(CheckLength(val))
        {
            var charset = "0123456789";
            if (!CheckChar(charset, input, false))
            {
                alert ("请输入文字！");
                document.forms[formTarget].elements[val].focus();
                document.forms[formTarget].elements[val].select();
                return false;
            }
            return true;
        }
    }
    else
    {
        return true;
    }
    return false;
}
//检测纯数字
function CheckNum(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

   if(!CheckLength(val))
       return false;
   if(isNaN(document.forms[formTarget].elements[val].value)) {
       alert ("请输入数字！");
       document.forms[formTarget].elements[val].focus();
       document.forms[formTarget].elements[val].select();
       return false;
   }
   return true;
}
//检测纯数字(可以为空)
function CheckNullNum(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

   if(isNaN(document.forms[formTarget].elements[val].value))
   {
       alert ("请输入数字！");
       document.forms[formTarget].elements[val].focus();
       document.forms[formTarget].elements[val].select();
       return false;
   }
   return true;
}
//检测正整数
function CheckNum2(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckLength(val))
       return false;
    var charset = "1234567890";
    var input = document.forms[formTarget].elements[val].value;
    if (!CheckChar(charset, input, true))
         {
            alert ("请输入整数！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
       return true;
}
function CheckFloatNum(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckLength(val))
       return false;
    var charset = "1234567890.";
    var input = document.forms[formTarget].elements[val].value;
    if (!CheckChar(charset, input, true))
         {
            alert ("请输入合法数据！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
       return true;
}
//检测正整数(可以为空)
function CheckNullNum2(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var charset = "1234567890";
    var input = document.forms[formTarget].elements[val].value;
    if (!CheckChar(charset, input, true))
    {
        alert ("请输入整数！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    var headChar = input.substring(0,1);
    if(headChar=="0")
    {
        alert("整数首位不可为0！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    return true;
}
//检测电话号码
function CheckPhone(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

   if(!CheckLength(val))
       return false;
   var input = document.forms[formTarget].elements[val].value;
   var charset = "1234567890-()";
   if (!CheckChar(charset, input, true)) {
       alert ("请输入电话号码，只可包含“-”、“()”和数字！");
       document.forms[formTarget].elements[val].focus();
       document.forms[formTarget].elements[val].select();
       return false;
   }
   return true;
}
//检查电话号码（可为空）
function CheckNullPhone(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

   var input = document.forms[formTarget].elements[val].value;
   var charset = "1234567890-()";
   if (!CheckChar(charset, input, true))
   {
       alert ("请输入电话号码，只可包含“-”、“()”和数字！");
       document.forms[formTarget].elements[val].focus();
       document.forms[formTarget].elements[val].select();
       return false;
   }
   return true;
}
//检测身份证
function CheckID(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckNum(val))
        return false;
    var input = document.forms[formTarget].elements[val].value;
    if ((input.length!=15) && (input.length!=18)) {
        alert ("请输入合法的身份证号码！长度为15或者18位");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    return true;
}
//检测身份证(可为空)
function CheckNullID(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
        if(!CheckNum(val)) return false;
        if((input.length!=15) && (input.length!=18))
        {
            alert ("请输入合法的身份证号码！长度为15或者18位");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
    }
    return true;
}
//检测货币并四舍五入
function CheckMoney(val,num,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckLength(val))
        return false;
    var input = document.forms[formTarget].elements[val].value;
    var pos1 = input.indexOf(".");
    var pos2 = input.lastIndexOf(".");
    var charset = "1234567890.";
    if ((pos1 != pos2)||(!CheckChar(charset, input, true))) {
        alert ("请输入金额，只可包含数字和一个“.”！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    if(num==null || num=="")
    {
        var output = eval((Math.round(input*100))/100);
        document.forms[formTarget].elements[val].value=output;
    }
    else
    {
        var i_exp=Math.pow(10,num)
        var output = eval((Math.round(input*i_exp))/i_exp);
        document.forms[formTarget].elements[val].value=output;
    }
    return true;
}
//检测货币并四舍五入（可以为空）
function CheckNullMoney(val,num,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
        if(!CheckLength(val))
            return false;

        var pos1 = input.indexOf(".");
        var pos2 = input.lastIndexOf(".");
        var charset = "1234567890.";
        if ((pos1 != pos2)||(!CheckChar(charset, input, true)))
        {
            alert ("请输入金额，只可包含数字和一个“.”！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        if(num==null || num=="")
        {
            var output = eval((Math.round(input*100))/100);
            document.forms[formTarget].elements[val].value=output;
        }
        else
        {
            var i_exp=Math.pow(10,num)
            var output = eval((Math.round(input*i_exp))/i_exp);
            document.forms[formTarget].elements[val].value=output;
        }
    }
    return true;
}
//检测 email
function CheckMail(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckLength(val))
        return false;
    var e = document.forms[formTarget].elements[val].value;
    var pos1 = e.indexOf("@");
    var pos2 = e.lastIndexOf("@");
    if (e.indexOf('@') == -1 || e.indexOf('.') == -1 || e.indexOf(' ') != -1||pos1!=pos2)
    {
        alert("请输入合法的电子邮件地址！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    return true;
}
//检测 email(可以为空)
function CheckNullMail(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var e = document.forms[formTarget].elements[val].value;
    if (e !="")
    {
        var pos1 = e.indexOf("@");
        var pos2 = e.lastIndexOf("@");
        if (e.indexOf('@') == -1 || e.indexOf('.') == -1 || e.indexOf(' ') != -1||pos1!=pos2)
        {
            alert("请输入合法的电子邮件地址！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        return true;
    }
    else
    {
        return true;
    }
}
//检测 email(可以为空)
function CheckMailCanNull(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var e = document.forms[formTarget].elements[val].value;
    if (e !="")
    {
        var pos1 = e.indexOf("@");
        var pos2 = e.lastIndexOf("@");
        if (e.indexOf('@') == -1 || e.indexOf('.') == -1 || e.indexOf(' ') != -1||pos1!=pos2)
        {
            alert("请输入合法的电子邮件地址！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        return true;
    }
    else
    {
        return true;
    }
}
/*检测密码是否一致*/
function CheckPwd(val1,val2,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var pwd1=document.forms[formTarget].elements[val1].value;
    var pwd2=document.forms[formTarget].elements[val2].value;
    if (pwd1.length<4)
    {
        alert('密码长度必须大于等于4位！');
        document.forms[formTarget].elements[val1].focus();
        document.forms[formTarget].elements[val1].select();
        return false;
    }
    if (pwd2.length<4)
    {
        alert('密码确认长度必须大于等于4位！');
        document.forms[formTarget].elements[val2].focus();
        document.forms[formTarget].elements[val2].select();
        return false;
    }
    if (pwd1!=pwd2)
    {
        alert("两次密码输入不一致！");
        document.forms[formTarget].elements[val1].focus();
        document.forms[formTarget].elements[val1].select();
        document.forms[formTarget].elements[val1].value="";
        document.forms[formTarget].elements[val2].value="";
        return false;
    }
    return true;
}
//日期校验
function CheckDate2(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckDate(document.forms[formTarget].elements[val].value)){
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    else
    {
        document.forms[formTarget].elements[val].value = CheckDate(document.forms[formTarget].elements[val].value);
    }
    return true;
}
//日期校验（可以为空）
function CheckNullDate2(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
        if(!CheckDate(input))
        {
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        else
        {
            document.forms[formTarget].elements[val].value = CheckDate(input);
        }
    }
    return true;
}
//检测日期
function  CheckDate(strDate, mini_year,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(mini_year == null) mini_year = 1900;
    var i_countSeparater = 0;
    var charset = "1234567890";
    var the_date = strDate;
    var the_dateLength=the_date.length;
    var i_firstSepLoc = the_date.indexOf('-',0);
    var i_lastSepLoc = the_date.lastIndexOf('-');
    if (i_firstSepLoc < 0 || i_firstSepLoc == i_lastSepLoc){
        alert('请输入“年-月-日”格式的正确时间！');
        return false;
    }
    var the_year = the_date.substring(0,i_firstSepLoc);
    var the_month = the_date.substring(i_firstSepLoc+1,i_lastSepLoc);
    var the_day = the_date.substring(i_lastSepLoc+1,the_dateLength);
    if (! CheckChar(charset, the_year, true)){
        alert('年份应为数字！');
        return false;
    }
    if (! CheckChar(charset, the_month, true)){
        alert('月份应为数字！');
        return false;
    }
    if (! CheckChar(charset, the_day, true)){
        alert('日期应为数字！');
        return false;
    }
    if (the_year.length >4){
        alert('年份不能大于4位！');
        return false;
    }else if (the_year.length == 1){
        the_year = '200'+the_year;
    }else if (the_year.length == 2){
        the_year = '20'+the_year;
    }else if (the_year.length == 3){
        the_year = '2'+the_year;
    }else if (the_year.length == 0){
        alert('请输入“年-月-日”格式的正确时间！');
        return false;
    }
    if (the_month.length > 2){
        alert('月份不能大于2位！');
        return false;
    }else if (the_month.length == 1){
        the_month = '0'+the_month;
    }else if (the_month.length ==0){
        alert('请输入由“-”分隔的正确的时间！');
        return false;
    }
    if (the_day.length > 2){
        alert('日期不能大于2位！');
        return false;
    }else if (the_day.length == 1){
        the_day = '0'+the_day;
    }else if (the_day.length == 0){
        alert('请输入由“-”分隔的正确的时间！');
        return false;
    }

    if ( the_year < mini_year){
        alert("年份不得小于 " + mini_year +"！");
        return false;
    }
    if (the_month < 01 || the_month > 12){
        alert("请输入正确的月份！")
        return false;
    }
    if (the_day >31 || the_day < 01){
        alert("请输入正确的日期！")
        return false;

    }else{
        switch(eval(the_month)) {
            case 4:
            case 6:
            case 9:
            case 11:
                if (the_day < 31){
                    the_date=the_year+'-'+the_month+'-'+the_day;
                    return the_date;
                }
                break;
            case 2:
                var num = Math.floor(the_year/4) * 4;
                if(the_year == num) {
                    if (the_day < 30){
                        the_date=the_year+'-'+the_month+'-'+the_day;
                        return the_date;
                     }
                } else {
                    if (the_day < 29){
                        the_date=the_year+'-'+the_month+'-'+the_day;
                        return the_date;
                    }
                }
                break;
            default:
                if (the_day < 32){
                    the_date=the_year+'-'+the_month+'-'+the_day;
                    return the_date;
                }
                break;
        }
    }
    alert("请输入正确的日期！");
    return false;

}
//检测小时，分钟
function CheckTime(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(!CheckHHMM(document.forms[formTarget].elements[val].value)){
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    else
    {
        document.forms[formTarget].elements[val].value = CheckHHMM(document.forms[formTarget].elements[val].value);
    }
    return true;
}
//检测小时，分钟 （可以为空）
function CheckNullTime(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
        if(!CheckHHMM(input))
        {
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        else
        {
            document.forms[formTarget].elements[val].value = CheckHHMM(input);
        }
    }
    return true;
}
//检测小时，分钟
function CheckHHMM(strHHMM,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;


        var the_HHMM = strHHMM;
        var charset = "1234567890";
        var the_HHMMLength = the_HHMM.length;
        var the_sepLoc = the_HHMM.indexOf(':',0);
        if (the_sepLoc < 0){
            alert('请输入由“:”分隔的正确的小时，分钟！');
            return false;

        }

        var the_HH = the_HHMM.substring(0,the_sepLoc);
        var the_MM = the_HHMM.substring(the_sepLoc+1,the_HHMMLength);
        if (! CheckChar(charset, the_HH, true)){
            alert('小时应为数字！');
            return false;
        }

        if (! CheckChar(charset, the_MM, true)){
            alert('分钟应为数字！');
            return false;
        }

        if (the_HH.length > 2){
            alert('小时不能大于2位！');
            return false;
        }else if (the_HH.length == 1){
            the_HH = '0'+the_HH;
        }else if (the_HH.length ==0){
            alert('请输入由“:”分隔的正确的小时，分钟！');
            return false;
        }

        if (the_MM.length > 2){
            alert('分钟不能大于2位！');
            return false;
        }else if (the_MM.length == 1){
            the_MM = '0'+the_MM;
        }else if (the_MM.length ==0){
            alert('请输入由“:”分隔的正确的小时，分钟！');
            return false;
        }

        if (the_HH > 23 || the_HH < 00){
            alert('请输入正确的小时！');
            return false;
        }

        if (the_MM > 60 || the_HH < 00){
            alert('请输入正确的分钟！');
            return false;
        }

        the_HHMM=the_HH + ":" + the_MM;
        return the_HHMM;
}
//去空格
function Trim(str)
{
    var num = str.length;
    var i = 0;
    for(i = 0; i < num;i++) {
        if(str.charAt(i) != " ")
            break;
    }
    str = str.substring(i);
    num = str.length;
    for(i = num-1; i > -1;i--) {
        if(str.charAt(i) != " ")
            break;
    }
    str = str.substring(0, i+1);
    return str;
}
//检查字符串中是否有规定字符以内/外的字符
function CheckChar(charset, val, should_in)
{
    var num = val.length;
    for (var i=0; i < num; i++) {
       var strchar = val.charAt(i);
       strchar = strchar.toUpperCase();
       if ((charset.indexOf(strchar) > -1) && (!should_in))
          return false;
       else if ((charset.indexOf(strchar) == -1) && (should_in))
          return false;
    }
    return true;
}
//不足长度的字符串补0
function Extend(val, length,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var str = "";
    str = document.forms[formTarget].elements[val].value;
    str = Trim(str);
    if(str.length == 0)
        return str;
    if(str.indexOf(" ") != -1){
        str = "";
    } else {
        var num = length - str.length;
        var zero = "";
        for(var i=0;i<num;i++)
           zero = zero + "0";
        str = zero + str;
    }
    document.forms[formTarget].elements[val].value = str;
    return str;
}
//TRIMALL 把所有的form 表单的输入字段去掉空格
function TrimForm(a_formName,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var formName = 0;
    if(a_formName!=null) formName=a_formName;
    var i_length = document.forms[formName].elements.length;
    for(var i=0; i<i_length; i++)
    if (document.forms[formName].elements[i].type == "text"||document.forms[formName].elements[i].type =="textarea")
        document.forms[formName].elements[i].value = Trim(document.forms[formName].elements[i].value);
}
//检验文本框中内容是否超长
function CheckTextareaLength(val, max_length,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var str_area=document.forms[formTarget].elements[val].value;
    if (str_area!=null&&str_area.length > max_length)
    {
        alert("字段文字超长，最多可输入" + max_length +"个字符，请重新输入！");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    return true;
}
//检查英文单引号
function CheckSingleQuotes(a_formName,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var formName = 0;
    if(a_formName!=null) formName=a_formName;
    for(var i=0; i<document.forms(formName).elements.length; i++)
    {
        if (document.forms[formName].elements[i].type == "text" || document.forms[formName].elements[i].type =="textarea" || document.forms[formName].elements[i].type =="password" || document.forms[formName].elements[i].type =="file")
        {
            str = Trim(document.forms[formName].elements[i].value);
            if (str.indexOf("\'") != -1)
            {
                alert ("请不要使用英文单引号！");
                document.forms[formName].elements[i].focus();
                document.forms[formName].elements[i].select();
                return false;
            }
        }
    }
    return true;
}
//提交到指定的url
function FormSubmit(url,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    document.forms[formTarget].action=url;
    document.forms[formTarget].submit();
}
function CheckCheckbox(val,msg1,msg2,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var is_radio=document.forms[formTarget].elements[val];
    var s_msg1=(msg1==null || msg1=="")? "请选择CheckBox!":msg1;
    var s_msg2=(msg2==null || msg2=="")? "没有可选的CheckBox!":msg2;

    if(is_radio)
    {
         if (document.forms[formTarget].elements[val].value != null)
         {
            if (document.forms[formTarget].elements[val].checked)
            {
                return true;
            }
            else
            {
                alert(s_msg1);
                return false;
            }
         }
         else
         {
            var check_length = document.forms[formTarget].elements[val].length;
            var i_count=0
            for(var i=0;i<check_length;i++)
            {
                if (document.forms[formTarget].elements[val][i].checked)
                {
                    i_count=i_count+1;
                    return true;
                }
            }
            if(i_count==0)
            {
                alert(s_msg1);
                return false;
            }
         }
    }//
    else
    {
        alert(s_msg2);
        return false;
    }

}
function CheckRadio(val,msg1,msg2,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var is_radio=document.forms[formTarget].elements[val];
    var s_msg1=(msg1==null || msg1=="")? "请选择 radio!":msg1;
    var s_msg2=(msg2==null || msg2=="")? "没有可选的 radio!":msg2;

    if(is_radio)
    {
         if (document.forms[formTarget].elements[val].value != null)
         {
            if (document.forms[formTarget].elements[val].checked)
            {
                return true;
            }
            else
            {
                alert(s_msg1);
                return false;
            }
         }
         else
         {
            var check_length = document.forms[formTarget].elements[val].length;
            var i_count=0
            for(var i=0;i<check_length;i++)
            {
                if (document.forms[formTarget].elements[val][i].checked)
                {
                    i_count=i_count+1;
                    return true;
                }
            }
            if(i_count==0)
            {
                alert(s_msg1);
                return false;
            }
         }
    }//
    else
    {
        alert(s_msg2);
        return false;
    }

}
//判断radio对象是否被选中
function CheckRadioIsSelected(val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var is_radio=document.forms[formTarget].elements[val];

    if(is_radio)
    {
         if (document.forms[formTarget].elements[val].value != null)
         {
            if (document.forms[formTarget].elements[val].checked)
            {
                return true;
            }
            else
            {
                return false;
            }
         }
         else
         {
            var check_length = document.forms[formTarget].elements[val].length;
            var i_count=0
            for(var i=0;i<check_length;i++)
            {
                if (document.forms[formTarget].elements[val][i].checked)
                {
                    i_count=i_count+1;
                    return true;
                }
            }
            if(i_count==0)
            {
                return false;
            }
         }
    }//
    else
    {
        return false;
    }
}
function CheckSelect(val,svalue,msg,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    if(document.forms[formTarget].elements[val].options[document.forms[formTarget].elements[val].selectedIndex].value==svalue )
    {
        alert(msg);
        return false;
    }
    else
    {
        return true;
    }

}
//检测不能为空
function CheckNull(val,formObj,msg)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(input!="")
    {
		return false;
    }
    else
    {   
		alert((msg==undefined?"此项不可为空!":msg));
        document.forms[formTarget].elements[val].focus();
        return true;
    }
    return false;
}

//检测输入日期是否早于当日日期    lzy2004/03/31
function checkForeTime(inputdate,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var now=new Date();
    var year = now.getYear();
    var month = now.getMonth() + 1;
    month = (month>9?"":"0") + month;
    var day = now.getDate();
    day = (day>9?"":"0") + day;
    var date = year+"-"+month+"-"+day;
    var indate = document.forms[formTarget].elements[inputdate].value;
    //alert("inputdate.value:"+indate);
    //alert("sysdate.value:" + date);
    //if(indate < date) alert("false");
    //else alert("true");
    if(indate < date){
        alert("输入的日期过期!");
        document.forms[formTarget].elements[inputdate].focus();
        return false; }
    else
        return true;
}

//检测身份证,isNull=true,则此项可以为空         lzy2004/03/31
function CheckIDNo(val,isNull,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var input = document.forms[formTarget].elements[val].value;
    if(isNull==null || isNull==true){
    	if(input =="") return true;
    }else{
    	if(!CheckLength(val)) return false;
    }


    if ((input.length!=15) && (input.length!=18)) {
        alert ("请输入合法的身份证号码！长度为15或者18位");
        document.forms[formTarget].elements[val].focus();
        document.forms[formTarget].elements[val].select();
        return false;
    }
    if(input.length==15){
    	if (!CheckChar('0123456789', input, true)){
    		alert ("身份证位数15时必须全是数字！");
        	return false;
        }
        else
        return true;
    }

    if(input.length==18){
    	var input17 = input.substring(0,17);
    	if (!CheckChar('0123456789', input17, true)) {
            alert ("身份证位数18时前17位必须是数字！");
            document.forms[formTarget].elements[val].focus();
            document.forms[formTarget].elements[val].select();
            return false;
        }
        else{
        	if('0123456789xX'.indexOf(input.substring(17))<0){
        		alert ("身份证位数18时最后一位必须是数字或字母X！");
        		return false;
        	}
        	return true;
        }


    }
}

function checkIPAddress (val,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

   var ipAddressString = document.forms[formTarget].elements[val].value;
   var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
   var passedTest = false;

   if (reSpaceCheck.test(ipAddressString)) {
    ipAddressString.match(reSpaceCheck);
    if (RegExp.$1 <= 255 && RegExp.$1 >= 0
      && RegExp.$2 <= 255 && RegExp.$2 >= 0
      && RegExp.$3 <= 255 && RegExp.$3 >= 0
      && RegExp.$4 <= 255 && RegExp.$4 >= 0) {
     passedTest = true;
    }
   }

   if (!passedTest) {
    alert('请输入合法的IP地址！');
    document.forms[formTarget].elements[val].focus();
    document.forms[formTarget].elements[val].select();
    return false;
   }

   return true;
  }

function CheckLengthNovalueForm(val,maxlen,formName,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

    var str = Trim(document.forms[formName].elements[val].value);
    if(str!="" && maxlen!=null)
    {
        if (str.length>maxlen)
        {
            alert("此项信息超长，最多可输入" + maxlen +"个字符，请重新输入！");
            document.forms[formName].elements[val].focus();
            document.forms[formName].elements[val].select();
            return false;
        }
    }
    if (str.indexOf("\'")!= -1) {
        alert ("请不要使用英文单引号！");
        document.forms[formName].elements[val].focus();
        document.forms[formName].elements[val].select();
        return false;
    }
    document.forms[formName].elements[val].value = str;
    return true;
}

function checkFileLength(file1,maxlen,formObj)
{
    //表单对象，如果为null，默认为“formEditor”
    var formTarget=(formObj==null || formObj=="" || typeof(formObj)=="undefined")? "formEditor":formObj;

	var fso = new ActiveXObject("Scripting.FileSystemObject");
	var f1 = fso.GetFile(document.forms[formTarget].elements[file1].value);
	if(f1.Size/1024 > maxlen){
		alert('选择的文件大小不能超过'+ maxlen + 'K 字节！');
		return false;
	}
	return true;
}
//============================================================================
//格式化输出数据，相当于ASP的FormatNumber()函数
//srcStr:需要格式化的数据;nAfterDot:小数位数
//直接截取,不舍 (ghost 2008-3-17)
//============================================================================
function FormatNumber(srcStr,nAfterDot){
    var srcStr,nAfterDot;
    var resultStr,nTen;
    srcStr = ""+srcStr+"";
    strLen = srcStr.length;
    dotPos = srcStr.indexOf(".",0);
    if (dotPos == -1){
        resultStr = srcStr+".";
        for (i=0;i<nAfterDot;i++){
            resultStr = resultStr+"0";
        }
        return resultStr;
    }
    else{
        if ((strLen - dotPos - 1) >= nAfterDot){
            nAfter = dotPos + nAfterDot + 1;
            nTen =1;
            for(j=0;j<nAfterDot;j++){
                nTen = nTen*10;
            }
            resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
            return resultStr;
        }
        else{
            resultStr = srcStr;
            for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
                resultStr = resultStr+"0";
            }
            return resultStr;
        }
    }
}
//保留两位小数，不足加0
function getTwoNumber(bb)
{
    s = bb.toString();
    l = s.indexOf(".");
    if(l<=0)
    {
        s=s+".00";
    }
    else if((s.length-l-1)==1)
    {
        s=s+"0";
    }
    return s;
}
//-->